<div class="tmd-doc">
<p></p>
<h1 class="tmd-header-1">
nil 1
</h1>
<p></p>
<div id="question" class="tmd-base">
<p></p>
<div class="tmd-usual">
What does the following program print?
</div>
<p></p>
<pre class="tmd-code line-numbers">
<code class="language-go">package main

var x = *new(*int)
var y *int = nil

func f() interface{} {
	return y
}

func main() {
	if f() == nil {
		if x == nil {
			println("A")
		} else {
			println("B")
		}
	} else {
		if x == nil {
			println("C")
		} else {
			println("D")
		}
	}
}
</code></pre>
</div>
<p></p>
<div class="tmd-usual">
Choices:
</div>
<p></p>
<input type="radio" id="choiceA" name="choice" class="choice">
<input type="radio" id="choiceB" name="choice" class="choice">
<input type="radio" id="choiceC" name="choice" class="choice">
<input type="radio" id="choiceD" name="choice" class="choice">

<div id="choices">

<ul style="list-style-type:none;">
<li><label for="choiceA">A</label></li>
<li><label for="choiceB">B</label></li>
<li><label for="choiceC">C</label></li>
<li><label for="choiceD">D</label></li>
</ul>

</div><p></p>
<div id="answer" class="tmd-base">
<div class="tmd-usual">
Answer: C
</div>
<p></p>
<div class="tmd-usual">
Run it on <a href="https://go.dev/play/p/imFfcWS711a">Go play</a>.
</div>
<p></p>
<div class="tmd-usual">
Key points:
</div>
<ul class="tmd-list">
<li class="tmd-list-item">
<div class="tmd-usual">
An interface value with a nil non-interface dynamic value is not a nil interface. So the function <code class="tmd-code-span">f</code> always return a non-nil interface value.
</div>
</li>
<li class="tmd-list-item">
<div class="tmd-usual">
A call to the <code class="tmd-code-span">new</code> builtin function always returns a pointer pointing to a zero value. That means dereferencing the pointer results in a zero value. The zero value of the <code class="tmd-code-span">*int</code> type is nil.
</div>
</li>
</ul>
<p></p>
</div>
<p></p>
</div>
